from loguru import logger
import time
import requests

TOKEN = "fueenfea5sijnnd4o8k4wmmprbalsp"


def get_daily_report():
    """
    每日早报接口
    :return:
    """
    res = requests.get("http://v3.alapi.cn/api/zaobao", params={"token": TOKEN, format: "json"}, verify=False)
    if res.status_code == 200:
        return res.json()["data"]
    else:
        logger.warning("每日早报接口 请求失败")
        return False


def get_daily_report_format():
    """
    每日早报格式化
    :return:
    """
    data = get_daily_report()
    if not data:
        return False

    data['date'] = data['date'].replace("-", "年").replace("-", "月") + "日"
    msg = f"每日早报 \r\n今天是:{data['date']} \r\n"
    for i in data['news']:
        msg += i + "\r\n"
    return msg


def get_tian_dog():
    """
    舔狗日记接口
    :return:
    """
    res = requests.get("http://v3.alapi.cn/api/dog", params={"token": TOKEN, format: "json"}, verify=False)
    if res.status_code == 200:
        return res.json()["data"]
    else:
        logger.warning("舔狗日记接口 请求失败")
        return False


def get_tian_dog_format():
    """
    舔狗日记格式化
    :return:
    """
    data = get_tian_dog()
    if not data:
        return False
    day = time.strftime("%Y年%m月%d日", time.localtime())
    return f"舔狗日记 \r\n今天是:{day}\r\n{data['content']}"

